<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>条件式调用</title>
</head>

<body>
  <script>
    function square(x, log) {
      if (log) {
        log(x)
        console.log(log(x));
      }
      return x * x
    }
    let m = function (a) {
      return a
    }
    console.log(square(1, m));

    function square1(x, log) {
      log?.(x)
      console.log(log?.(x));
      return x * x
    }
    console.log(square1(2,));


    let m1 = null, x = 0;
    try {
      m1(x++)
      console.log(m1(x++));
    } catch (e) {
      console.log(x);
    }
    console.log(m1?.(x++));
    console.log(x);


    let o = {
      a: function fn() {
        return 5
      }
    }
    console.log(o.a());


    let l
    console.log(l?.a());


    let c = {}
    console.log(c.a?.());


  </script>
</body>

</html>